function findAllQuestion(cid){
	var params={
			"cid":cid	
	};
	sessionStorage.cate=cid;
	$.ajax({
        "contentType": "application/json; charset=utf-8",
        "type": "POST",
        "url": "allQuestion",
        "data": JSON.stringify(params),   
        "success": function (data,textStatus) {
        	console.log(cid);
       //     console.log(data);
            $("#localCate").text("当前选择的课程：课程"+sessionStorage.cate);
            $("#question").empty();
            for(var i in data){
        		var p=$("<button></button>");
        		var p2=$("<p></p>");
        		var p3=$("<p></p>");
        		var qid=data[i].qid;
        		var uid=data[i].uid;
        		var qtime=data[i].qtime;
        		var title=data[i].title;
        		var detail=data[i].detail
        		p.text(qid+"提问人：用户"+uid+ " "+"提问时间: "+timestampToTime(qtime));
        		p2.text("标题："+title)
        		p3.text("内容："+detail)
        		$("#question").append(p);
        		$("#question").append(p2);
        		$("#question").append(p3);
        		(function(qid){
        			p.click(function(){
        			
            			findAllAnswer(qid);
            		});
        		})(qid);  
            } 
        }
    });
}
function addOneQuestion(){
	var params={
			"cid":sessionStorage.cate,
			"uid":sessionStorage.myUid,
			"detail":$("#detailArea").val(),
			"title":$("#titleArea").val()
	};
	if(sessionStorage.cate<1){
		alert("请选择一门课程")
	}else{
	if(($("#detailArea").val()).length>250||($("#titleArea").val()).length>30||($("#detailArea").val()).length==0||($("#titleArea").val()).length==0){
		alert("输入字串为空或过长")
	}else{
	$.ajax({
        "contentType": "application/json; charset=utf-8",
        "type": "POST",
        "url": "oneQuestion",
        "data": JSON.stringify(params),   
        "success": function (data,textStatus) {
            console.log(data);
            if(data){
            	alert("添加成功");
            }else{
            	alert("添加失败");
            }
            
        }
    });
	}}
}
function timestampToTime(timestamp) {
	var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	Y = date.getFullYear() + '/';
	M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date
			.getMonth() + 1)
			+ '/';
	D = date.getDate() + ' ';
	h = date.getHours() + ':';
	m = date.getMinutes() + ':';
	s = date.getSeconds();
	return Y + M + D + h + m + s;
}
